package com.groupbuying.currency.consumer.mq;

import com.aliyun.openservices.ons.api.ONSFactory;
import com.aliyun.openservices.ons.api.Producer;
import com.aliyun.openservices.ons.api.PropertyKeyConst;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * class_name: CurrencyMQProducer
 * package: com.groupbuying.currency.consumer.mq
 * description: 积分中心 - MQ生产者
 * creat_user: Ywxd
 * creat_date: 2019/5/20
 * creat_time: 15:24
 **/
@Configuration
public class CurrencyMQProducer {

    public static final Logger LOGGER = LoggerFactory.getLogger(CurrencyMQProducer.class);

    public CurrencyMQProducer() {
    }

    @Bean
    public Producer getCurrencyMQProducer() {
        Properties properties = new Properties();
        properties.put(PropertyKeyConst.AccessKey, CurrencyMQConfig.ACCESS_KEY);
        properties.put(PropertyKeyConst.SecretKey, CurrencyMQConfig.SECRET_KEY);
        properties.put(PropertyKeyConst.NAMESRV_ADDR, CurrencyMQConfig.NAMESRV_ADDR);
        Producer producer = ONSFactory.createProducer(properties);
        try {
            producer.start();
            LOGGER.info("currency producer is start !!!  groupId:{" + CurrencyMQConfig.GROUP_ID + "}");
        } catch (Exception exception) {
            LOGGER.error(String.format("currency producer is error  groupId:{" + CurrencyMQConfig.GROUP_ID + "}", exception.getMessage(), exception));
        }

        return producer;
    }
}
